# 主模块：接受用户从控制台输入的字符串
def main():
    input_string = input("请输入一个字符串：")

    # letter 模块：接收字符串，将字符串中的非英文字符剔除
    def letter(input_string):
        letter_string = ''.join(filter(str.isalpha, input_string))
        return letter_string

    letter_string = letter(input_string)

    # reverse 模块：将接收到的全英文字符反转
    def reverse(s):
        return s[::-1]

    reversed_string = reverse(letter_string)
    print(reversed_string)

    # encode 模块：使用凯撒密码算法对已反转的字符加密后输出
    def encode(s, key):
        result = ''
        for char in s:
            if 'a' <= char <= 'z':
                shifted_char = chr(((ord(char) - ord('a') + key) % 26) + ord('a'))
            elif 'A' <= char <= 'Z':
                shifted_char = chr(((ord(char) - ord('A') + key) % 26) + ord('A'))
            else:
                shifted_char = char
            result += shifted_char
        return result

    encoded_string = encode(reversed_string, 3)

    print("加密后的字符串：", encoded_string)

if __name__ == "__main__":
    main()
